/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package it.apuliait.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.util.PortalUtil;

import it.apuliait.service.ClpSerializer;
import it.apuliait.service.RiceventeLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Method;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Donatello
 */
public class RiceventeClp extends BaseModelImpl<Ricevente> implements Ricevente {
	public RiceventeClp() {
	}

	@Override
	public Class<?> getModelClass() {
		return Ricevente.class;
	}

	@Override
	public String getModelClassName() {
		return Ricevente.class.getName();
	}

	@Override
	public long getPrimaryKey() {
		return _riceventeId;
	}

	@Override
	public void setPrimaryKey(long primaryKey) {
		setRiceventeId(primaryKey);
	}

	@Override
	public Serializable getPrimaryKeyObj() {
		return _riceventeId;
	}

	@Override
	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("riceventeId", getRiceventeId());
		attributes.put("userId", getUserId());
		attributes.put("codiceIpa", getCodiceIpa());
		attributes.put("nomeRic", getNomeRic());
		attributes.put("cognomeRic", getCognomeRic());
		attributes.put("ragioneSocialeRic", getRagioneSocialeRic());
		attributes.put("codFiscaleRic", getCodFiscaleRic());
		attributes.put("pIvaRic", getPIvaRic());
		attributes.put("nazioneRic", getNazioneRic());
		attributes.put("codEoriRic", getCodEoriRic());
		attributes.put("indirizzoSedeRic", getIndirizzoSedeRic());
		attributes.put("civicoSedeRic", getCivicoSedeRic());
		attributes.put("capSedeRic", getCapSedeRic());
		attributes.put("comuneSedeRic", getComuneSedeRic());
		attributes.put("provinciaSedeRic", getProvinciaSedeRic());
		attributes.put("nazioneSedeRic", getNazioneSedeRic());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long riceventeId = (Long)attributes.get("riceventeId");

		if (riceventeId != null) {
			setRiceventeId(riceventeId);
		}

		Long userId = (Long)attributes.get("userId");

		if (userId != null) {
			setUserId(userId);
		}

		String codiceIpa = (String)attributes.get("codiceIpa");

		if (codiceIpa != null) {
			setCodiceIpa(codiceIpa);
		}

		String nomeRic = (String)attributes.get("nomeRic");

		if (nomeRic != null) {
			setNomeRic(nomeRic);
		}

		String cognomeRic = (String)attributes.get("cognomeRic");

		if (cognomeRic != null) {
			setCognomeRic(cognomeRic);
		}

		String ragioneSocialeRic = (String)attributes.get("ragioneSocialeRic");

		if (ragioneSocialeRic != null) {
			setRagioneSocialeRic(ragioneSocialeRic);
		}

		String codFiscaleRic = (String)attributes.get("codFiscaleRic");

		if (codFiscaleRic != null) {
			setCodFiscaleRic(codFiscaleRic);
		}

		String pIvaRic = (String)attributes.get("pIvaRic");

		if (pIvaRic != null) {
			setPIvaRic(pIvaRic);
		}

		String nazioneRic = (String)attributes.get("nazioneRic");

		if (nazioneRic != null) {
			setNazioneRic(nazioneRic);
		}

		String codEoriRic = (String)attributes.get("codEoriRic");

		if (codEoriRic != null) {
			setCodEoriRic(codEoriRic);
		}

		String indirizzoSedeRic = (String)attributes.get("indirizzoSedeRic");

		if (indirizzoSedeRic != null) {
			setIndirizzoSedeRic(indirizzoSedeRic);
		}

		String civicoSedeRic = (String)attributes.get("civicoSedeRic");

		if (civicoSedeRic != null) {
			setCivicoSedeRic(civicoSedeRic);
		}

		String capSedeRic = (String)attributes.get("capSedeRic");

		if (capSedeRic != null) {
			setCapSedeRic(capSedeRic);
		}

		String comuneSedeRic = (String)attributes.get("comuneSedeRic");

		if (comuneSedeRic != null) {
			setComuneSedeRic(comuneSedeRic);
		}

		String provinciaSedeRic = (String)attributes.get("provinciaSedeRic");

		if (provinciaSedeRic != null) {
			setProvinciaSedeRic(provinciaSedeRic);
		}

		String nazioneSedeRic = (String)attributes.get("nazioneSedeRic");

		if (nazioneSedeRic != null) {
			setNazioneSedeRic(nazioneSedeRic);
		}
	}

	@Override
	public long getRiceventeId() {
		return _riceventeId;
	}

	@Override
	public void setRiceventeId(long riceventeId) {
		_riceventeId = riceventeId;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setRiceventeId", long.class);

				method.invoke(_riceventeRemoteModel, riceventeId);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public long getUserId() {
		return _userId;
	}

	@Override
	public void setUserId(long userId) {
		_userId = userId;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setUserId", long.class);

				method.invoke(_riceventeRemoteModel, userId);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
	}

	@Override
	public void setUserUuid(String userUuid) {
		_userUuid = userUuid;
	}

	@Override
	public String getCodiceIpa() {
		return _codiceIpa;
	}

	@Override
	public void setCodiceIpa(String codiceIpa) {
		_codiceIpa = codiceIpa;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setCodiceIpa", String.class);

				method.invoke(_riceventeRemoteModel, codiceIpa);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getNomeRic() {
		return _nomeRic;
	}

	@Override
	public void setNomeRic(String nomeRic) {
		_nomeRic = nomeRic;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setNomeRic", String.class);

				method.invoke(_riceventeRemoteModel, nomeRic);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getCognomeRic() {
		return _cognomeRic;
	}

	@Override
	public void setCognomeRic(String cognomeRic) {
		_cognomeRic = cognomeRic;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setCognomeRic", String.class);

				method.invoke(_riceventeRemoteModel, cognomeRic);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getRagioneSocialeRic() {
		return _ragioneSocialeRic;
	}

	@Override
	public void setRagioneSocialeRic(String ragioneSocialeRic) {
		_ragioneSocialeRic = ragioneSocialeRic;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setRagioneSocialeRic",
						String.class);

				method.invoke(_riceventeRemoteModel, ragioneSocialeRic);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getCodFiscaleRic() {
		return _codFiscaleRic;
	}

	@Override
	public void setCodFiscaleRic(String codFiscaleRic) {
		_codFiscaleRic = codFiscaleRic;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setCodFiscaleRic", String.class);

				method.invoke(_riceventeRemoteModel, codFiscaleRic);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getPIvaRic() {
		return _pIvaRic;
	}

	@Override
	public void setPIvaRic(String pIvaRic) {
		_pIvaRic = pIvaRic;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setPIvaRic", String.class);

				method.invoke(_riceventeRemoteModel, pIvaRic);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getNazioneRic() {
		return _nazioneRic;
	}

	@Override
	public void setNazioneRic(String nazioneRic) {
		_nazioneRic = nazioneRic;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setNazioneRic", String.class);

				method.invoke(_riceventeRemoteModel, nazioneRic);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getCodEoriRic() {
		return _codEoriRic;
	}

	@Override
	public void setCodEoriRic(String codEoriRic) {
		_codEoriRic = codEoriRic;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setCodEoriRic", String.class);

				method.invoke(_riceventeRemoteModel, codEoriRic);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getIndirizzoSedeRic() {
		return _indirizzoSedeRic;
	}

	@Override
	public void setIndirizzoSedeRic(String indirizzoSedeRic) {
		_indirizzoSedeRic = indirizzoSedeRic;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setIndirizzoSedeRic",
						String.class);

				method.invoke(_riceventeRemoteModel, indirizzoSedeRic);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getCivicoSedeRic() {
		return _civicoSedeRic;
	}

	@Override
	public void setCivicoSedeRic(String civicoSedeRic) {
		_civicoSedeRic = civicoSedeRic;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setCivicoSedeRic", String.class);

				method.invoke(_riceventeRemoteModel, civicoSedeRic);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getCapSedeRic() {
		return _capSedeRic;
	}

	@Override
	public void setCapSedeRic(String capSedeRic) {
		_capSedeRic = capSedeRic;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setCapSedeRic", String.class);

				method.invoke(_riceventeRemoteModel, capSedeRic);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getComuneSedeRic() {
		return _comuneSedeRic;
	}

	@Override
	public void setComuneSedeRic(String comuneSedeRic) {
		_comuneSedeRic = comuneSedeRic;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setComuneSedeRic", String.class);

				method.invoke(_riceventeRemoteModel, comuneSedeRic);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getProvinciaSedeRic() {
		return _provinciaSedeRic;
	}

	@Override
	public void setProvinciaSedeRic(String provinciaSedeRic) {
		_provinciaSedeRic = provinciaSedeRic;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setProvinciaSedeRic",
						String.class);

				method.invoke(_riceventeRemoteModel, provinciaSedeRic);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getNazioneSedeRic() {
		return _nazioneSedeRic;
	}

	@Override
	public void setNazioneSedeRic(String nazioneSedeRic) {
		_nazioneSedeRic = nazioneSedeRic;

		if (_riceventeRemoteModel != null) {
			try {
				Class<?> clazz = _riceventeRemoteModel.getClass();

				Method method = clazz.getMethod("setNazioneSedeRic",
						String.class);

				method.invoke(_riceventeRemoteModel, nazioneSedeRic);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public BaseModel<?> getRiceventeRemoteModel() {
		return _riceventeRemoteModel;
	}

	public void setRiceventeRemoteModel(BaseModel<?> riceventeRemoteModel) {
		_riceventeRemoteModel = riceventeRemoteModel;
	}

	public Object invokeOnRemoteModel(String methodName,
		Class<?>[] parameterTypes, Object[] parameterValues)
		throws Exception {
		Object[] remoteParameterValues = new Object[parameterValues.length];

		for (int i = 0; i < parameterValues.length; i++) {
			if (parameterValues[i] != null) {
				remoteParameterValues[i] = ClpSerializer.translateInput(parameterValues[i]);
			}
		}

		Class<?> remoteModelClass = _riceventeRemoteModel.getClass();

		ClassLoader remoteModelClassLoader = remoteModelClass.getClassLoader();

		Class<?>[] remoteParameterTypes = new Class[parameterTypes.length];

		for (int i = 0; i < parameterTypes.length; i++) {
			if (parameterTypes[i].isPrimitive()) {
				remoteParameterTypes[i] = parameterTypes[i];
			}
			else {
				String parameterTypeName = parameterTypes[i].getName();

				remoteParameterTypes[i] = remoteModelClassLoader.loadClass(parameterTypeName);
			}
		}

		Method method = remoteModelClass.getMethod(methodName,
				remoteParameterTypes);

		Object returnValue = method.invoke(_riceventeRemoteModel,
				remoteParameterValues);

		if (returnValue != null) {
			returnValue = ClpSerializer.translateOutput(returnValue);
		}

		return returnValue;
	}

	@Override
	public void persist() throws SystemException {
		if (this.isNew()) {
			RiceventeLocalServiceUtil.addRicevente(this);
		}
		else {
			RiceventeLocalServiceUtil.updateRicevente(this);
		}
	}

	@Override
	public Ricevente toEscapedModel() {
		return (Ricevente)ProxyUtil.newProxyInstance(Ricevente.class.getClassLoader(),
			new Class[] { Ricevente.class }, new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		RiceventeClp clone = new RiceventeClp();

		clone.setRiceventeId(getRiceventeId());
		clone.setUserId(getUserId());
		clone.setCodiceIpa(getCodiceIpa());
		clone.setNomeRic(getNomeRic());
		clone.setCognomeRic(getCognomeRic());
		clone.setRagioneSocialeRic(getRagioneSocialeRic());
		clone.setCodFiscaleRic(getCodFiscaleRic());
		clone.setPIvaRic(getPIvaRic());
		clone.setNazioneRic(getNazioneRic());
		clone.setCodEoriRic(getCodEoriRic());
		clone.setIndirizzoSedeRic(getIndirizzoSedeRic());
		clone.setCivicoSedeRic(getCivicoSedeRic());
		clone.setCapSedeRic(getCapSedeRic());
		clone.setComuneSedeRic(getComuneSedeRic());
		clone.setProvinciaSedeRic(getProvinciaSedeRic());
		clone.setNazioneSedeRic(getNazioneSedeRic());

		return clone;
	}

	@Override
	public int compareTo(Ricevente ricevente) {
		long primaryKey = ricevente.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof RiceventeClp)) {
			return false;
		}

		RiceventeClp ricevente = (RiceventeClp)obj;

		long primaryKey = ricevente.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(33);

		sb.append("{riceventeId=");
		sb.append(getRiceventeId());
		sb.append(", userId=");
		sb.append(getUserId());
		sb.append(", codiceIpa=");
		sb.append(getCodiceIpa());
		sb.append(", nomeRic=");
		sb.append(getNomeRic());
		sb.append(", cognomeRic=");
		sb.append(getCognomeRic());
		sb.append(", ragioneSocialeRic=");
		sb.append(getRagioneSocialeRic());
		sb.append(", codFiscaleRic=");
		sb.append(getCodFiscaleRic());
		sb.append(", pIvaRic=");
		sb.append(getPIvaRic());
		sb.append(", nazioneRic=");
		sb.append(getNazioneRic());
		sb.append(", codEoriRic=");
		sb.append(getCodEoriRic());
		sb.append(", indirizzoSedeRic=");
		sb.append(getIndirizzoSedeRic());
		sb.append(", civicoSedeRic=");
		sb.append(getCivicoSedeRic());
		sb.append(", capSedeRic=");
		sb.append(getCapSedeRic());
		sb.append(", comuneSedeRic=");
		sb.append(getComuneSedeRic());
		sb.append(", provinciaSedeRic=");
		sb.append(getProvinciaSedeRic());
		sb.append(", nazioneSedeRic=");
		sb.append(getNazioneSedeRic());
		sb.append("}");

		return sb.toString();
	}

	@Override
	public String toXmlString() {
		StringBundler sb = new StringBundler(52);

		sb.append("<model><model-name>");
		sb.append("it.apuliait.model.Ricevente");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>riceventeId</column-name><column-value><![CDATA[");
		sb.append(getRiceventeId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userId</column-name><column-value><![CDATA[");
		sb.append(getUserId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>codiceIpa</column-name><column-value><![CDATA[");
		sb.append(getCodiceIpa());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>nomeRic</column-name><column-value><![CDATA[");
		sb.append(getNomeRic());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>cognomeRic</column-name><column-value><![CDATA[");
		sb.append(getCognomeRic());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>ragioneSocialeRic</column-name><column-value><![CDATA[");
		sb.append(getRagioneSocialeRic());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>codFiscaleRic</column-name><column-value><![CDATA[");
		sb.append(getCodFiscaleRic());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>pIvaRic</column-name><column-value><![CDATA[");
		sb.append(getPIvaRic());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>nazioneRic</column-name><column-value><![CDATA[");
		sb.append(getNazioneRic());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>codEoriRic</column-name><column-value><![CDATA[");
		sb.append(getCodEoriRic());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>indirizzoSedeRic</column-name><column-value><![CDATA[");
		sb.append(getIndirizzoSedeRic());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>civicoSedeRic</column-name><column-value><![CDATA[");
		sb.append(getCivicoSedeRic());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>capSedeRic</column-name><column-value><![CDATA[");
		sb.append(getCapSedeRic());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>comuneSedeRic</column-name><column-value><![CDATA[");
		sb.append(getComuneSedeRic());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>provinciaSedeRic</column-name><column-value><![CDATA[");
		sb.append(getProvinciaSedeRic());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>nazioneSedeRic</column-name><column-value><![CDATA[");
		sb.append(getNazioneSedeRic());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _riceventeId;
	private long _userId;
	private String _userUuid;
	private String _codiceIpa;
	private String _nomeRic;
	private String _cognomeRic;
	private String _ragioneSocialeRic;
	private String _codFiscaleRic;
	private String _pIvaRic;
	private String _nazioneRic;
	private String _codEoriRic;
	private String _indirizzoSedeRic;
	private String _civicoSedeRic;
	private String _capSedeRic;
	private String _comuneSedeRic;
	private String _provinciaSedeRic;
	private String _nazioneSedeRic;
	private BaseModel<?> _riceventeRemoteModel;
}